package day2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Arrays;

public class exe {
    public static void main(String[] args) {
        //demo2();
        //demo1();
        //demo3();
        try(
                FileInputStream fis=new FileInputStream("d://CloudMusic//wyyun//MV//EXO.mp4");
                FileOutputStream fos=new FileOutputStream("d://CloudMusic//wyyun//MV//EXO1.mp4"))
        {
            long totalSize = new File("d://CloudMusic//wyyun//MV//EXO.mp4").length();
            long copiedSize = 0; // 每次循环累加已复制字节数
            int lastPercent = -1;
            long start=System.currentTimeMillis();
            int len;
            byte[] bs=new byte[1024];
            while ((len=fis.read(bs))!=-1){
                fos.write(bs,0,len);
                copiedSize += len;    // 更新已复制大小
                int currentPercent = (int) ((copiedSize * 100) / totalSize);
                if (currentPercent % 10 == 0 && currentPercent > lastPercent) {
                    System.out.println("已完成: " + currentPercent + "%");
                    lastPercent = currentPercent;  // 避免重复打印
                }
            }
            if (lastPercent < 100) {
                System.out.println("已完成: 100%");
            }
            long end=System.currentTimeMillis();
            System.out.println("复制成功"+(end-start)+"ms");
        }catch (IOException e){
            e.printStackTrace();
        }

    }
    public static void demo1(){
        for(int i=2;i<=100;i++){
            boolean suShu=true;
            for(int j=2;j<i;j++){
                if(i%j==0){
                    suShu=false;
                    break;
                }
            }
            if(suShu){
                System.out.print(i+" ");
            }
        }
    }
    //选择排序：第一个元素和其他人进行比较 目的求出第一个元素是最小的 然后第二个元素和其他比较 目的求出第二个最小的
    public static void demo2(){
        int ary[]=new int[]{4,5,6,7,2,9,10};
        for(int i=0;i<= ary.length;i++){
            for(int j=i+1;j< ary.length;j++){
                if(ary[i]>ary[j]){
                    int temp=ary[i];
                    ary[i]=ary[j];
                    ary[j]=temp;
                }
            }

        }
        System.out.println(Arrays.toString(ary));
    }
    public static void demo3(){

}}
